package com.ks.phone.wedget;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.animation.Animation;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;

import com.ks.phone.R;
import com.ks.phone.databinding.DialogTipBinding;

import razerdp.basepopup.BasePopupWindow;
import razerdp.util.animation.AnimationHelper;
import razerdp.util.animation.ScaleConfig;

public class PopupTip extends BasePopupWindow {

    private DialogTipBinding mBinding;

    public final ObservableField<String> strContent = new ObservableField<>();

    public PopupTip(Context context) {
        super(context);
        setContentView(R.layout.dialog_tip);
        setPopupGravity(Gravity.CENTER);
        setAutoMirrorEnable(true);      // 如果当前屏幕不足以完整显示您的PopupWindow，则PopupWindow会自行布置在其镜像位置。
        setBlurBackgroundEnable(false); // 设置PopupWindow弹出时是否模糊背景
//        setBackground(null);            // 设置无背景
        setOutSideDismiss(false);
        setBackPressEnable(false);
        setOutSideTouchable(false);
    }


    @Override
    public void onViewCreated(@NonNull View contentView) {
        mBinding = DialogTipBinding.bind(contentView);
        mBinding.setPopup(this);

        strContent.set("查询手机录音文件夹失败，请进行如下步骤操作：\n" +
                "  1、手机开启自动录音功能；\n" +
                "  2、用手机拨打一通电话，手机会自动进行录音；\n" +
                "  3、挂断电话重启app；");
    }

    public void setContent(String content) {
        strContent.set(content);
    }

    public void setOnConfirmClickListener(View.OnClickListener listener) {
        mBinding.tvConfirm.setOnClickListener(listener);
    }

    @Override
    protected Animation onCreateShowAnimation() {
        return AnimationHelper.asAnimation()
                .withScale(ScaleConfig.CENTER)
                .toShow();
    }

    @Override
    protected Animation onCreateDismissAnimation() {
        return AnimationHelper.asAnimation()
                .withScale(ScaleConfig.CENTER)
                .toDismiss();
    }
}
